<template>
  <div class="login">
    <div style="margin-left: 20px;">
        <br/><br/>
        用 户 名：<el-input v-model="login.userNumber" style="width:70%" placeholder="请输入用户名" ></el-input><br/><br/>
        密 &nbsp;&nbsp;&nbsp;&nbsp;码：<el-input v-model="login.passWord" style="width:70%" placeholder="请输入密码"  show-password></el-input><br/><br/>
        <el-button type="primary" @click="loginGo">登录</el-button><el-button type="primary" @click="()=>{$router.push({ path: '../CreateUser/' })}">注册账号</el-button>
    </div>
  </div>
</template>

<script>
import{get} from './util/request'
import {Register} from './config/Login'
import{encryptByDES} from './util/md5'
export default {
    data () {
        return {
            login:{
                passWord:'',
                userNumber:'',
            }
        }
    },created () {
        
    },methods: {
        loginGo(){
            const user=this.login;
            user.passWord=encryptByDES(user.passWord)
            get(Register,user)
                .then(response=>{
                    if(response.statusCode==200){
                        sessionStorage.setItem("isPower",false);
                        sessionStorage.setItem("user",JSON.stringify(response.value.user));
                        sessionStorage.setItem("token",response.value.token);
                        this.$router.push({ path: '../Chat/' });
                    }else{
                        this.$message.error(response.message)
                    }
                })
        }
    }
}
</script>
<style>
.login{
    background-color:beige;
    width:500px; 
    height:500px; 
    margin-left: 60%;
    margin-top: 10px;
}
</style>